package Solution101_200.problem111.MinimumDepthofBinaryTree;

import common.TreeNode;
import org.junit.Test;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/12 14:26
 */
public class Solution {

    /**
     * 对叶子节点的理解，两边都没有子树的才是叶子节点
     * @param root
     * @return
     */
    public int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        if(root.left==null&&root.right==null){
            return 1;
        }
        if(root.left==null){
            return 1+minDepth(root.right);
        }
        if(root.right==null){
            return 1+minDepth(root.left);
        }
        return Math.min(minDepth(root.left),minDepth(root.right))+1;
    }
}
